package com.orcamento;

import java.util.ArrayList;

import org.joda.time.DateTime;

import com.orcamento.entity.Account;
import com.orcamento.entity.Category;
import com.orcamento.entity.CreditCard;
import com.orcamento.entity.Event;
import com.orcamento.entity.Exchange;
import com.orcamento.entity.Fund;
import com.orcamento.entity.Gain;
import com.orcamento.entity.Installment;
import com.orcamento.entity.Invoice;
import com.orcamento.entity.Spent;
import com.orcamento.entity.enums.InvoiceStatusEnum;
import com.orcamento.entity.enums.Month;
import com.orcamento.util.Money;

public class DomainUtils {

	public static Account getAccount(Long id, String name, String login, String password) {
		Account account = new Account();
		account.setId(id);
		account.setName(name);
		account.setLogin(login);
		account.setPassword(password);
		return account;
	}
	
	public static Account getValidAccount(Long id) {
		Account account = new Account();
		account.setId(id);
		account.setName("Richard");
		account.setLogin("richardsbrandao@gmail.com");
		account.setPassword("321321");
		return account;
	}

	public static Event getEvent(Long id, String name, String description) {
		Event event = new Event();
		event.setId(id);
		event.setName(name);
		event.setDescription(description);
		event.setActive(true);
		
		Account account = new Account();
		account.setId(1L);
		event.setAccount(account);
		return event;
	}

	public static Gain getGain(Long id, Money value, DateTime receivedDay, Event event, Fund fund) {
		Gain gain = new Gain();
		gain.setId(id);
		gain.setValue(value);
		gain.setReceivedDay(receivedDay);
		gain.setEvent(event);
		gain.setFund(fund);
		
		Account account = new Account();
		account.setId(1L);
		gain.setAccount(account);
		return gain;
	}
	
	public static Spent getSpent(Long id, Money value, DateTime spentDay, Event event, Fund fund) {
		Spent spent = new Spent();
		spent.setId(id);
		spent.setValue( value );
		spent.setSpentDay(spentDay);
		spent.setEvent(event);
		spent.setFund(fund);
		
		Account account = new Account();
		account.setId(1L);
		spent.setAccount(account);
		return spent;
	}

	public static Fund getFund(Long id, Long idEvent, Money startMoney) {
		Fund fund = new Fund();
		fund.setId(id);
		fund.setEvent( getEvent(idEvent, null, null) );
		fund.setStartMoney(startMoney);
		fund.setStatus(true);
		
		Account account = new Account();
		account.setId(1L);
		fund.setAccount(account);
		return fund;
	}

	public static Exchange getExchange(Long id, Long idFundOrigin, Long idFundDestiny, Money value, DateTime date) {
		Exchange exchange = new Exchange();
		exchange.setId(id);
		exchange.setValue( value );
		exchange.setDate(date);
		Fund origin = new Fund();
		origin.setId(idFundOrigin);
		exchange.setOrigin(origin);
		Fund destiny = new Fund();
		destiny.setId(idFundDestiny);
		exchange.setDestiny(destiny);
		
		Account account = new Account();
		account.setId(1L);
		exchange.setAccount(account);
		return exchange;
	}

	public static Category getCategory(Long id, String name) {
		Category category = new Category();
		category.setId(id);
		category.setName(name);

		Account account = new Account();
		account.setId(1L);
		category.setAccount(account);
		return category;
	}

	public static CreditCard getCreditCard(Long id, String name, String coverage, String brand) {
		CreditCard creditCard = new CreditCard();
		creditCard.setId(id);
		creditCard.setName(name);
		creditCard.setCoverage(coverage);
		creditCard.setBrand( brand );
		creditCard.setActive(true);
		creditCard.setInvoices( new ArrayList<Invoice>() );
		Account account = new Account();
		account.setId(1L);
		creditCard.setAccount(account);
		return creditCard;
	}

	public static Invoice getInvoice(Long id, Month month, Integer year, Money limit) {
		Invoice invoice = new Invoice();
		invoice.setId(id);
		if(month != null) { 
			invoice.setMonth( month.id ); 
		}
		invoice.setYear(year);
		invoice.setLimit(limit);
		invoice.setStatus(InvoiceStatusEnum.ABERTO);
		
		Account account = new Account();
		account.setId(1L);
		invoice.setAccount(account);
		return invoice;
	}

	public static Installment getValidInstallment(Long accountId) {
		Account account = new Account();
		account.setId(accountId);
		
		Spent spent = new Spent();
		spent.setId(2L);
		spent.setAccount(account);
		
		Invoice invoice = new Invoice();
		invoice.setId(5L);	
		invoice.setAccount(account);
		
		Installment installment = new Installment(2, new Money(5), spent, invoice);
		installment.setId(1L);
		
		return installment;
	}

}
